package org.cbg.panel;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;

import org.cbg.btn.TraslationMyMainMygoodsBtn;
import org.cbg.frame.TrslationMainJframe;
import org.cbg.until.TraslationTableMygoodsUntil;
import org.come.until.CutButtonImage;

import com.tool.tcpimg.UIUtils;



/**
 * 藏宝阁 我的藏宝阁 我的货物
 * 
 * @author Administrator
 * 
 */

public class TraslationMyMainMygoodsJpanel extends JPanel {

    /**
     * 页码,快速取回
     */
    private JLabel yema;
    private TraslationMyMainMygoodsBtn kuaisuquhui,lianxiMaiJia;
    /**
     * 页码按钮，首页，末页 , 左箭头, 右箭头
     */
    private TraslationMyMainMygoodsBtn shouye, moye, leftArrows, rightArrows;

    private JScrollPane jScrollPane;
    /**
     * 当前页数 最大页码
     */
    private int dangqianyeshu = 1, zuidayema = 50;

    /**
     * 全选框， 勾选
     */
    private JLabel quanxuankuang, gouxuan;

    public TraslationMyMainMygoodsJpanel() {
        /**
         * 面板设置
         */
        this.setPreferredSize(new Dimension(760, 460));
        this.setOpaque(false);
        this.setLayout(null);

        /**
         * 初始化组件
         */
        jScrollPane = new JScrollPane();
        kuaisuquhui = new TraslationMyMainMygoodsBtn("inkImg/number/b4/qbqhaj.png", 1, UIUtils.COLOR_BTNTEXT,
                UIUtils.TEXT_FONT, 1, "", this);

        lianxiMaiJia = new TraslationMyMainMygoodsBtn("inkImg/number/b4/kbaj.png", 1, UIUtils.COLOR_BTNPUTONG1,
                UIUtils.TEXT_FONT, 1, "联系卖家", this);

        yema = new JLabel(dangqianyeshu + "/" + zuidayema);
        shouye = new TraslationMyMainMygoodsBtn("inkImg/number/b4/fy1.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, 2,
                "", this);
        moye = new TraslationMyMainMygoodsBtn("inkImg/number/b4/fy4.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, 3,
                "", this);
        leftArrows = new TraslationMyMainMygoodsBtn("inkImg/number/b4/fy2.png", 1, 4, this);
        rightArrows = new TraslationMyMainMygoodsBtn("inkImg/number/b4/fy3.png", 1, 5, this);
        gouxuan = new JLabel();
        quanxuankuang = new JLabel();
        /**
         * 设置不可见
         */
        jScrollPane.setOpaque(false);
        kuaisuquhui.setOpaque(false);
        yema.setOpaque(false);
        shouye.setOpaque(false);
        leftArrows.setOpaque(false);
        moye.setOpaque(false);
        rightArrows.setOpaque(false);
        gouxuan.setOpaque(false);
        quanxuankuang.setOpaque(false);

        /**
         * 设置边框透明
         */
        jScrollPane.setBorder(null);
        kuaisuquhui.setBorder(null);
        shouye.setBorder(null);
        leftArrows.setBorder(null);
        moye.setBorder(null);
        rightArrows.setBorder(null);

        /**
         * 设置位置与大小
         */
        jScrollPane.setBounds(8, 63, 750, 372);
        lianxiMaiJia.setBounds(12, 5, 120, 40);
        kuaisuquhui.setBounds(12, 5, 95, 26);
        yema.setBounds(258+91, 442, 58, 17);
        shouye.setBounds(287, 442, 40, 20);
        leftArrows.setBounds(326, 442, 19, 20);
        moye.setBounds(433, 442, 40, 20);
        rightArrows.setBounds(411, 442, 19, 20);
        gouxuan.setBounds(25, 40, 15, 15);
        quanxuankuang.setBounds(25, 40, 17, 16);

        /**
         * 更改字体颜色
         */
        yema.setForeground(UIUtils.COLOR_cbg8);

        /**
         * 修改JScrollPane，并添加组件
         */
        TraslationTableMygoodsUntil.TableModel(jScrollPane, 10);
        jScrollPane.getVerticalScrollBar().setUnitIncrement(50);

        /**
         * 设置图片
         */
        gouxuan.setIcon(null);
        quanxuankuang.setIcon(CutButtonImage.getImage("inkImg/number/b4/gxk.png", 17, 16));
        /**
         * 设置内容居中
         */
        yema.setHorizontalAlignment(SwingConstants.CENTER);

        /**
         * 设置名字
         */
        gouxuan.setName("1");

        /**
         * 面板添加组件
         */
        this.add(jScrollPane);
        this.add(kuaisuquhui);
        this.add(yema);
        this.add(shouye);
        this.add(leftArrows);
        this.add(moye);
        this.add(rightArrows);
        this.add(gouxuan);
        this.add(quanxuankuang);

        gouxuan.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if ("1".equals(gouxuan.getName())) {
                    gouxuan.setIcon(CutButtonImage.getImage("skin/8100226/button/13.png", 15, 15));
                    gouxuan.setName("0");

                    TrslationMainJframe.getTrslationMainJframe().setGoodsGouxuangeshu(
                            TrslationMainJframe.getTrslationMainJframe().getGoodsGeshuMax());
                    /**
                     * 全选时所有的消息勾选框都要勾选
                     */
                    JPanel view = (JPanel) jScrollPane.getViewport().getView();
                    Component[] components = view.getComponents();
                    for (int i = 0; i < components.length; i++) {
                        JPanel panel = (JPanel) components[i];
                        JLabel component2 = (JLabel) panel.getComponent(3);
                        if (component2.isVisible()) {
                            component2.setName("0");
                            component2.setIcon(CutButtonImage.getImage("skin/8100226/button/13.png", 15, 15));
                        }
                    }
                } else {
                    gouxuan.setIcon(null);
                    gouxuan.setName("1");

                    TrslationMainJframe.getTrslationMainJframe().setGoodsGouxuangeshu(0);
                    /**
                     * 全选时所有的消息勾选框都要取消勾选
                     */
                    JPanel view = (JPanel) jScrollPane.getViewport().getView();
                    Component[] components = view.getComponents();
                    for (int i = 0; i < components.length; i++) {
                        JPanel panel = (JPanel) components[i];
                        JLabel component2 = (JLabel) panel.getComponent(3);
                        if (component2.isVisible()) {
                            component2.setName("1");
                            component2.setIcon(null);
                        }
                    }
                }

            }
        });

    }

    private ImageIcon icon;

    /**
     * 画图
     */
    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon == null) {
            icon = new ImageIcon("inkImg/number/b4/wdhwxq.png");

        }
        g.drawImage(icon.getImage(), 0, 5, 760, 55, this);
        //Delete.Deletexcbg();
    }
    /**
     * 获取最大页数并刷新页码
     *
     * @param zuidayema
     */
    public void setPage(int zuidayema) {
        this.zuidayema = zuidayema;
        yema.setText(dangqianyeshu + "/" + zuidayema);
    }

    public JLabel getYema() {
        return yema;
    }

    public void setYema(JLabel yema) {
        this.yema = yema;
    }

    public TraslationMyMainMygoodsBtn getShouye() {
        return shouye;
    }

    public void setShouye(TraslationMyMainMygoodsBtn shouye) {
        this.shouye = shouye;
    }

    public TraslationMyMainMygoodsBtn getMoye() {
        return moye;
    }

    public void setMoye(TraslationMyMainMygoodsBtn moye) {
        this.moye = moye;
    }

    public TraslationMyMainMygoodsBtn getLeftArrows() {
        return leftArrows;
    }

    public void setLeftArrows(TraslationMyMainMygoodsBtn leftArrows) {
        this.leftArrows = leftArrows;
    }

    public TraslationMyMainMygoodsBtn getRightArrows() {
        return rightArrows;
    }

    public void setRightArrows(TraslationMyMainMygoodsBtn rightArrows) {
        this.rightArrows = rightArrows;
    }

    public JScrollPane getjScrollPane() {
        return jScrollPane;
    }

    public void setjScrollPane(JScrollPane jScrollPane) {
        this.jScrollPane = jScrollPane;
    }

    public int getDangqianyeshu() {
        return dangqianyeshu;
    }

    public void setDangqianyeshu(int dangqianyeshu) {
        this.dangqianyeshu = dangqianyeshu;
    }

    public int getZuidayema() {
        return zuidayema;
    }

    public void setZuidayema(int zuidayema) {
        this.zuidayema = zuidayema;
    }

    public TraslationMyMainMygoodsBtn getKuaisuquhui() {
        return kuaisuquhui;
    }

    public void setKuaisuquhui(TraslationMyMainMygoodsBtn kuaisuquhui) {
        this.kuaisuquhui = kuaisuquhui;
    }

    public JLabel getQuanxuankuang() {
        return quanxuankuang;
    }

    public void setQuanxuankuang(JLabel quanxuankuang) {
        this.quanxuankuang = quanxuankuang;
    }

    public JLabel getGouxuan() {
        return gouxuan;
    }

    public void setGouxuan(JLabel gouxuan) {
        this.gouxuan = gouxuan;
    }

}
